<?php

namespace App\Services\Admin;

use App\Models\CarouselImage as CarouselImageModel;

class CarouselImage extends Base
{
    /**
     * @param $type_id
     * @param $type 1:課程表輪播圖  2：科室表輪播圖
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public static function lists($type_id, $type)
    {

        $input = request()->all();

        $where[] = ['type', $type];
        $where[] = [self::type_result($type), $type_id];

        return (new CarouselImageModel)->where($where)->orderBy('order', 'asc')->paginate(6);

    }

    public static function info($id)
    {
        return (new CarouselImageModel)->where('id', $id)->first();
    }

    public static function add($param = [])
    {
        return (new CarouselImageModel)->insert($param);
    }

    public static function edit($id, $param = [])
    {
        return (new CarouselImageModel)->where('id', $id)->update($param);
    }

    public static function del($id)
    {
        return (new CarouselImageModel)->where('id', $id)->delete();
    }

    /**
     * 輪播類型區分
     * @param string $type
     * @return mixed|string
     */
    public static function type_result($type = '')
    {
        $result = [
            '1'=>'class_base_id',
            '2'=>'classroom_id',
        ];

        return $result[$type];
    }
}
